package com.orcwar.gui.views;

import android.content.ClipData;
import android.content.ClipData.Item;
import android.content.ClipDescription;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.orcwar.R;
import com.orcwar.enums.OWUnitClass;
import com.orcwar.enums.SpriteEnum;

public class OWClassDescriptionView extends LinearLayout {

	private OWUnitClass unitClass = null;

	public OWClassDescriptionView(Context context, AttributeSet attrs) {
		super(context, attrs);

		setOnLongClickListener(new OnLongClickListener() {

			@Override
			public boolean onLongClick(View v) {
				// start dragging!
				Item item = new Item(
						OWClassDescriptionView.this.unitClass.toString());
				ClipData dragData = new ClipData(item.getText(),
						new String[] { ClipDescription.MIMETYPE_TEXT_PLAIN },
						item);
				Log.d(OWClassDescriptionView.class.getName(), "Dragging : "
						+ item.getText());
				v.startDrag(dragData, new DragShadowBuilder(v), null, 0);
				return true;
			}
		});
	}

	public void init(OWUnitClass unitClass) {
		this.unitClass = unitClass;

		TextView className = (TextView) findViewById(R.id.className);
		TextView classStats = (TextView) findViewById(R.id.classStats);
		TextView classDescription = (TextView) findViewById(R.id.classDescription);
		ImageView sprite = (ImageView) findViewById(R.id.classSprite);

		className.setText(unitClass.getName(getContext()));
		classDescription.setText(unitClass.toString() + " et puis blablabla");

		switch (unitClass) {
		case BOUCLIEUR:
			sprite.setImageBitmap(SpriteEnum.UNIT_BOUCLIEUR.getBitmap());
			classStats.setText("MP : 4 / AP : 1 ");
			break;

		case FLEAUTEUR:
			sprite.setImageBitmap(SpriteEnum.UNIT_FLEAUTEUR.getBitmap());
			classStats.setText("MP : 3 / AP : 1 ");
			break;

		case HACHEUR:
			sprite.setImageBitmap(SpriteEnum.UNIT_HACHEUR.getBitmap());
			classStats.setText("MP : 5 / AP : 2 ");
			break;

		case HOMMELANCE:
			sprite.setImageBitmap(SpriteEnum.UNIT_HOMMELANCE.getBitmap());
			classStats.setText("MP : 4 / AP : 1 ");
			break;

		case TIREUR:
			sprite.setImageBitmap(SpriteEnum.UNIT_TIREURDELOIN.getBitmap());
			classStats.setText("MP : 2 / AP : 1 ");
			break;

		default:
			break;
		}
	}

}
